package com.iyeed.jbpm03.demo07.decision;

import java.io.FileNotFoundException;

import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.junit.Test;

import com.iyeed.jbpm03.demo07.decision.handler.DecisionDelegationHandler;
import com.iyeed.util.PackageUtils;

public class DecisionTest {
	
	@Test
	public void testDecisionExpression() throws FileNotFoundException {
		ProcessDefinition pd = ProcessDefinition.parseXmlResource(PackageUtils.getPackageNameForRelativePath(this.getClass()) + "/jpdl/decisionexpression/processdefinition.xml");
		ProcessInstance pi = new ProcessInstance(pd);
		//根据此条件，绝对执行那条Transition
		pi.getContextInstance().setVariable("transName", "thirdT");
		Token token = pi.getRootToken();
		token.signal();
	}
	
	
	/**
	 * 根据DecisionHandler决定选择Transition
	 * @see DecisionDelegationHandler
	 * @throws FileNotFoundException
	 */
	@Test
	public void testDecisionDelegation() throws FileNotFoundException {
		ProcessDefinition pd = ProcessDefinition.parseXmlResource(PackageUtils.getPackageNameForRelativePath(this.getClass()) + "/jpdl/decisiondelegation/processdefinition.xml");
		ProcessInstance pi = new ProcessInstance(pd);
		Token token = pi.getRootToken();
		token.signal();
	}
	
	
	@Test
	public void testDecisionTransitionCondition() throws FileNotFoundException {
		ProcessDefinition pd = ProcessDefinition.parseXmlResource(PackageUtils.getPackageNameForRelativePath(this.getClass()) + "/jpdl/decisiontransitioncondition/processdefinition.xml");
		ProcessInstance pi = new ProcessInstance(pd);
		//根据此条件，绝对执行那条Transition
//		pi.getContextInstance().setVariable("param", new Integer(10));
		pi.getContextInstance().setVariable("param", new Integer(20));
//		pi.getContextInstance().setVariable("param", new Integer(30));
		Token token = pi.getRootToken();
		token.signal();
	}
	
}
